﻿
<?php
require ('../config.php');

//获取页面传递的充值参数
$faveValue = $_POST['faceValue'];
$pd_id = $_POST['channelId'];
$card_id = $_POST['cardId'];
$card_pass = $_POST['cardPass'];

//同步和异步跳转地址
$notify_url = "http://" . dirname(dirname($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'])) . "/notify_url.php";
$result_url = "http://" . dirname(dirname($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'])) . "/result_url.php";

//设置充值方式
$kdPay->setPayChannel($pd_id);
//设置金额
$kdPay->setFaveValue($faveValue);
//设置同步和异步地址
$kdPay->setNotifyAndResult($notify_url, $result_url);
//设置卡号卡密
$kdPay->setCard($card_id, $card_pass);

$channelId = $kdPay->getPayChannel();

$redirect_url = $kdPay->getRedirectUrl(2);

$return_msg = curl_post($redirect_url);
$return_code = explode("=", $return_msg);
$order_id = $kdPay->getOrder();





/***************************
 * 以下为所需函数
 *
 */

function curl_post($url)
{

    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    $output = curl_exec($ch);

    curl_close($ch);
    return $output;
}

//通道类型
function getChannelname($channelid)
{
    switch($channelid){
        case "4":
            echo "腾讯QB卡";
            break;
        case "5":
            echo "盛大一卡通";
            break;
        case "6":
            echo "骏网一卡通";
            break;
        case "7":
            echo "完美一卡通";
            break;
        case "8":
            echo "搜狐一卡通";
            break;
        case "9":
            echo "征途游戏卡";
            break;
        case "10":
            echo "久游一卡通";
            break;
        case "11":
            echo "网易一卡通";
            break;
        case "12":
            echo "光宇一卡通";
            break;
        case "13":
            echo "电信充值卡";
            break;
        case "14":
            echo "移动充值卡";
            break;
        case "15":
            echo "联通充值卡";
            break;
        case "16":
            echo "纵游一卡通";
            break;
        case "17":
            echo "天宏一卡通";
            break;
        case "18":
            echo "天下一卡通";
            break;
    }
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>支付结果页</title>
<link rel="stylesheet" href="../images/app_style.css"  type="text/css" />
    <script type="text/javascript" src="../images/jquery-1.11.3.min.js"></script>
<style type="text/css">
    p{
        color: red;
        display: inline;
        font-weight: bold;
    }
</style>
</head>
<script type="text/javascript">
    $(function () {
        function checkOrderStatus() {
            var order_status = $("#orderStatus");
            var order = $("#order_id").text();
            var money = $("#faceValue").text();
            var card = $("#card_id").text();
            var channel = $("#channel_id").val();


        if('<?=$return_code[1]?>' != '0')
        {

            order_status.html('<p>充值失败！</p>错误码:<p style="font-size:larger"><?=$return_code[1]?></p>&nbsp;请查看对接手册了解错误信息');
        }
        else
        {
            $.ajax({
                url: "../query.php",
                data:{"order":order,"channel":channel,"money":money,"card":card,"rid":Math.random()},
                dataType:"json",
                success:function (data) {
                    if(data.flag == 1 && dafa.status ==1)
                    {
                        order_status.html('充值成功！');
                        clearInterval(check);
                    }
                    else if(data.flag==0)
                    {
                        order_status.html('<p>充值失败！</p>');
                        clearInterval(check);
                    }


                }

            });

        }


        }
        var check = setInterval(checkOrderStatus,3000);

    })
</script>
<body>
<div id="wrap">
<table width="100%" height="34" border="0" align="center" cellpadding="0" cellspacing="0" style="margin-top:20px">
  <tr>
    <td width="33%"><img src="../images/logo-pay.jpg" /></td>
	<td width="68%" valign="bottom"><span class="logotxt">支付结果</span></td>
  </tr>
</table>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="1" class="mytable">
      <tr>
        <td width="100" height="25" align="right">订单号：</td>
        <td><span id="order_id"><?=$order_id?></span></td>
      </tr>
	  <tr>
        <td width="100" height="25" align="right">充值类别：</td>
        <td>
            <? getChannelname($channelId)?>
            <input type="hidden" value="<?=$channelId?>" id="channel_id">
        </td>
      </tr>
	  <tr>
        <td width="100" height="25" align="right">卡号：</td>
        <td ><span id="card_id"><?=$card_id?></span></td>
      </tr>
	  <tr>
        <td width="100" height="25" align="right">卡密：</td>
        <td><?=$card_pass?></td>
      </tr>
	  <tr>
        <td width="100" height="25" align="right">支付金额：</td>
        <td><font style="font-size:14px; font-family:Geneva, Arial, Helvetica, sans-serif;color:#FF0000; font-weight:bold"><span id="faceValue"><?=$faveValue?></span></font> 元</td>
      </tr>
	  <tr>
        <td width="100" height="25" align="right">订单状态：</td>
        <td><span id="orderStatus"><img src="../images/onLoad.gif" align="middle" />正在处理..</span></td>
      </tr>
	  <tr><td colspan="2" align="center" style="color:#FF0000">注意：如果未正常返回订单结果，请复制订单号联系客服</td></tr>
	  <tr><td colspan="2" align="center"><input type="button" value="关闭" onclick="window.close()"/></td></tr>
</table>
    <br />
</div>
</body>
</html>

